// test-computation-v1.ts

// Helper Constants
const PI = 3.14159;
const GRAVITY = 9.81;

// Helper Functions
function circleArea(radius: number): number {
  return PI * radius * radius;
}

function calculateDistance(initialVelocity: number, time: number): number {
  // Simple physics calculation: d = v*t + 0.5*a*t^2 (assuming a = GRAVITY)
  return initialVelocity * time + 0.5 * GRAVITY * time * time;
}

function generateSequence(start: number, count: number, step: number): number[] {
  const sequence: number[] = [];
  for (let i = 0; i < count; i++) {
    sequence.push(start + i * step);
  }
  return sequence;
}

function processData(data: { values: number[], factor: number }): { sum: number, average: number } {
    const sum = data.values.reduce((acc, val) => acc + val * data.factor, 0);
    const average = data.values.length > 0 ? sum / data.values.length : 0;
    return { sum, average };
}

// Main export object
const computationResult = {
  title: "Computation Test v1",
  constants: {
    piValue: PI,
    gravityValue: GRAVITY,
  },
  calculations: {
    areaOfCircleRadius5: circleArea(5),
    areaOfCircleRadius10: circleArea(10),
    distanceTravelled: calculateDistance(20, 5), // v=20, t=5
  },
  generated: {
    sequence1: generateSequence(1, 5, 2), // [1, 3, 5, 7, 9]
    sequence2: generateSequence(10, 3, -1), // [10, 9, 8]
  },
  dataAnalysis: processData({
    values: [10, 20, 30, 40, 50],
    factor: 2,
  }), // Should calculate sum=(10*2+20*2+...) and average
  nestedComputation: {
    inputTime: 15,
    calculatedDistance: calculateDistance(0, 15), // v=0, t=15
    derivedArea: circleArea(15 / PI) // Use nested input
  }
};

export default computationResult; 